define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'myadmin/company/scorelog/index',
                    add_url: 'myadmin/company/scorelog/add',
                    edit_url: 'myadmin/company/scorelog/edit',
                    del_url: 'myadmin/company/scorelog/del',
                    multi_url: 'myadmin/company/scorelog/multi',
                    table: 'company_score_log',
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        {field: 'id', title: __('Id'), width: '90', operate: false, visible: false},
                        { field: 'createtime', width: '170', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
                        {
                            field: 'company_id', title: __('Company'), formatter: Table.api.formatter.search,
                            formatter: function (value, row, index) {
                                if (row.company) {
                                    return '<a href="javascript:;" class="searchit" data-field="company_id" data-value="' + row.company_id + '">' + row.company.name + '</a>';
                                }
                                return '-';
                            },
                            searchList: function (column) { return Template('company', {}); },
                        },
                        { field: 'memo', title: __('Memo'), formatter: Table.api.formatter.search, align: 'left' },
                        { field: 'score', width: '120', title: __('Score'), operate: 'BETWEEN', formatter: Table.api.formatter.search },
                        { field: 'before', width: '120', title: __('Before'), operate: false, formatter: Table.api.formatter.search },
                        { field: 'after', width: '120', title: __('After'), operate: false, formatter: Table.api.formatter.search },
                        { field: 'operate', width: '100', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        myCommon: function () {},
        add: function() {
            this.myCommon();
            Controller.api.bindevent();
        },
        edit: function() {
            this.myCommon();
            Controller.api.bindevent();
        },
        api: {
            bindevent: function() {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});